<template>
  <div>
   <h2>登录</h2>
   <hr>
   <table border="1">
    <tr>
      <td align="right">账号:</td>
      <td>
        <input type="text" v-model="state.Name">
      </td>
    </tr>
    <tr>
      <td align="right">密码:</td>
      <td>
        <input type="password" v-model="state.Pwd">
      </td>
    </tr>
    <tr>
      <td align="right">
        <input type="button" value="登录" @click="Login">
      </td>
      <td>
        <input type="button" value="注册">
      </td>
    </tr>
   </table>
  </div>
</template>

<script setup lang="ts">
import{reactive,toRefs,onMounted} from 'vue';
import{useRouter,useRoute} from 'vue-router';
import axios from 'axios';

const router=useRouter();
const route=useRoute();

let data:any=reactive({
  state:{
    Name:'',
    Pwd:''
  }
})
let {state}=toRefs(data);

function Login(){
  let obj={
    Name:state.value.Name,
    Pwd:state.value.Pwd
  }
axios({
  url:'https://localhost:7145/api/Member/Login',
  method:'post',
  params:obj
})
.then(res=>{
  if(res.data.data==-1)
{
  alert('账号名不存在')
  return
}
if(res.data.data>0)
{
  alert('登录成功')
  router.push('/FangHaoAdd')
}
else{
  alert('登录失败')
  return
}
})
.catch(err=>{
  console.log(err)
})

}





</script>

<style scoped>

</style>